<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>验证码倒计时</title>
    <script>
        window.onload=function () {
            let btnEle = document.getElementById("btn");
            // 绑定事件
            btnEle.onclick=function () {
                let time=5
                btnEle.disabled=true;
                btnEle.innerHTML=time+"秒后重新发送";
                // 创建一个定时器
                let interval = setInterval(function () {
                    time--;
                    btnEle.innerHTML=time+"秒后重新发送";
                    if(time==0){
                        // 清除定时器
                        clearInterval(interval);
                        btnEle.innerHTML="发送验证码";
                        btnEle.disabled=false;
                    }
                },1000);
            }
        }
    </script>
</head>
<body>
<input type="text">
<button id="btn">发送验证码</button>
</body>
</html>